import Cookies from 'js-cookie'
const TOKEN_NAME = process.env.VUE_APP_TOKEN_NAME
const TOP_USER_ID = process.env.VUE_APP_TOP_USER_ID
const LAST_PATH = 'lastPath'
const FIRST_PATH = 'firstPath'
const USER_ID = 'userId'
export function setToken(token) {
    Cookies.set(TOKEN_NAME,token)
}

export function getToken() {
    return Cookies.get(TOKEN_NAME)
}

//设置推荐人
export function setTopUser(topUserId) {
    Cookies.set(TOP_USER_ID,topUserId)
}

export function getTopUserId() {
    let str = Cookies.get(TOP_USER_ID)
    // if(str instanceof Array){
    //     str = str[0]
    // }
    if(str&&str.indexOf("[")>-1){
        str = JSON.parse(str)[0]
    }
    return str
}

//设置上次URL
export function setLastPath(path) {
    Cookies.set(LAST_PATH,path)
}

export function getLastPath() {
    return Cookies.get(LAST_PATH)
}

//设置首次URL
export function setFirstPath(path) {
    Cookies.set(FIRST_PATH,path)
}

export function getFirstPath() {
    return Cookies.get(FIRST_PATH)
}

//设置用户ID
export function setUserId(userId) {
    Cookies.set(USER_ID,userId)
}

export function getUserId() {
    return  Cookies.get(USER_ID)
}